/**
 * Author: Jackin (qin.zhang@uni.lu)
 * Date: 2013
 * (c) 2013 University of Luxembourg - Interdisciplinary Centre for Security Reliability and Trust (SnT)
 * All rights reserved
 * GPLv3 to be found at: http://www.gnu.org/licenses/quick-guide-gplv3.html
 */

package lu.uni.geko.ext.ram;

import java.util.HashSet;
import java.util.Set;

import lu.uni.geko.resources.MainResourceLoader;
import lu.uni.geko.util.datastructures.BiHashN2NMap;
import lu.uni.geko.util.datastructures.BiN2NMap;
import lu.uni.geko.weaver.AdviceEffectuation;
import lu.uni.geko.weaver.HashMappedAdviceEffectuation;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;

/**
 *
 *
 * @author Jackin
 *
 */
public final class RamAdviceEffectuationCalculator
{

	/**
	 * Utility class doesn't provide public constructor.
	 */
	private RamAdviceEffectuationCalculator()
	{

	}
	
	public static AdviceEffectuation calculateAdviceEffectuation(URI baseURI, int instantiationIndex)
	{
		ram.Aspect base = (ram.Aspect) MainResourceLoader.getUniqueContentRoot(baseURI, "current base model");
		ram.Instantiation instantiation = base.getInstantiations().get(instantiationIndex);
		ram.Aspect dependent = instantiation.getExternalAspect();
		
		dependent.getInstantiations().clear();
		dependent.setLayout(null);
		
		Set<EObject> baseElementsToRemove = new HashSet<EObject>(); // nothing to be removed during weaving RAM aspects
		Set<EObject> avElementsToAdd = calculateAvElementsToAdd(dependent);
		BiN2NMap<EObject, EObject> base2AdviceMergeBiN2NMap = calculateBase2AdviceMergeBiN2NMap(base, dependent, instantiation);
		
		
		return new HashMappedAdviceEffectuation(baseElementsToRemove, avElementsToAdd, base2AdviceMergeBiN2NMap);
	}
	
	private static Set<EObject> calculateAvElementsToAdd(ram.Aspect dependent)
	{
		Set<EObject> avElementsToAdd = new HashSet<EObject>();
		
		return avElementsToAdd;
	}
	
	private static BiN2NMap<EObject, EObject> calculateBase2AdviceMergeBiN2NMap(ram.Aspect base, ram.Aspect dependent, ram.Instantiation instantiation)
	{
		BiN2NMap<EObject, EObject> base2AdviceMergeBiN2NMap = new BiHashN2NMap<EObject, EObject>();

		return base2AdviceMergeBiN2NMap;
	}
}
